<!--
 * @Date: 2019-12-26 11:44:30
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2020-05-07 15:41:44
 * @describe: -转为合同-
 -->
<template>
  <div class="stateUpdate">
    <el-form :model="dataForm" label-width="100px" label-position="left">
      <el-form-item label="合同状态">
        <ren-select
          v-model="dataForm.state"
          dict-type="contractState"
          placeholder="合同状态"
          class="FormSelect"
          style="width:100%"
        ></ren-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="stateUpdateFun" style="width:100%;" type="primary">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  name: "",
  data() {
    return {
      dataForm: {
        state: "",
        id: this.intentionId
      }
    };
  },
  props: ["intentionId"],
  created() {
    this.getInfo();
  },
  mounted() {},
  methods: {
    // 获取数据
    getInfo() {
      this.$http
        .get("/intention/intentioninfo/" + this.intentionId)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
        })
        .catch(() => {});
    },

    //修改核心
    stateUpdateFun() {
      this.$http
        .post("/intention/intentioninfo/saveContract", this.dataForm)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.$message({
            message: this.$t("prompt.success"),
            type: "success",
            duration: 500,
            onClose: () => {
               this.$refs["dataForm"].resetFields();
            }
          });
        })
        .catch(() => {});
    },
    //判断操作权限
    hasPermissionInfo(val) {
      let _this = this;
      let arr = _this.permissionListDTO;
      if (arr && arr != []) {
        for (let i = 0; i < arr.length; i++) {
          const element = arr[i];
          if (element.permission.indexOf(val) != -1 && element.state == true) {
            return true;
          }
        }
      } else {
        return false;
      }
    }
  },
  watch: {
    intentionId: {
      handler(newValue, oldValue) {
        this.dataForm.id = this.intentionId;
        this.getInfo();
      }
    }
  }
};
</script>
<style scoped>
.stateUpdate {
  width: 500px;
  margin: auto;
}
</style>